package aod.android.com.bernay.mine.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;

import aod.android.com.bernay.R;
import aod.android.com.bernay.mine.module.AlbumBean;
import aod.android.com.bernay.mine.module.AlbumInnerBean;
import aod.android.com.bernay.mine.module.DynamicBean;

/**
 * @author crated by zhixianuanyang on 2019/4/14 13:09
 * @Email jamesKing0812@gmail.com
 */
public class AlbumAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final Context mContext;
    private final List<AlbumBean> albumsList;
    private boolean isShow;
    private OnItemClickListener onItemClickListener;
    private OnItemLongClickListener onItemLongClickListener;

    public AlbumAdapter(Context context, List<AlbumBean> albumsList) {
        this.mContext = context;
        this.albumsList = albumsList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater mInflater = LayoutInflater.from(mContext);
        View view = mInflater.inflate(R.layout.album_list_item, parent, false);
        return new AlbumViewHolder(view,mContext);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof AlbumViewHolder ){
            AlbumBean albumBean = albumsList.get(position);
            ((AlbumViewHolder) holder).bindData(albumBean,position,isShow);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener !=null){
                    onItemClickListener.onItemClick(position);
                }
                if (onItemLongClickListener !=null){
                    onItemLongClickListener.onItemLongClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return albumsList.size();
    }

    public void showSelected(boolean isShow) {
        this.isShow = isShow;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    public interface OnItemLongClickListener {
        void onItemLongClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickListener) {
        this.onItemLongClickListener = onItemLongClickListener;
    }
}
